<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
            <a-form-item label="招生年度">
              <a-select showSearch optionFilterProp="children" v-model="queryParam.zsnj" @change="xnChange">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
            <a-form-item label="院系">
              <a-select :disabled="selectMenu.yx.length === 1" :allowClear="true" showSearch optionFilterProp="children"
                        v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{i.dwh+'-'+ i.dwmc }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="专业">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkzydm"
                          @change='zyChange'>
                  <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="研究方向">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.bkyjfxm">
                  <a-select-option v-for="i in selectMenu.yjfx" :key="i.id" :value="i.yjfxm">{{
                    i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="准考证号">
                <a-input placeholder="请输入..." v-model="queryParam.ksbh"/>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="考生姓名">
                <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="统考科目一">
                <a-row :gutter="0" style="overflow:hidden">
                  <a-col span="12">
                    <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zzllcjfw">
                      <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                    </a-select>
                  </a-col>
                  <a-col span="12">
                    <a-input placeholder="请输入..." v-model="queryParam.zzllcj"/>
                  </a-col>
              </a-row>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="统考科目二">
                <a-row :gutter="0" style="overflow:hidden">
                  <a-col span="12">
                    <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.wgycjfw">
                      <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                    </a-select>
                  </a-col>
                  <a-col span="12">
                    <a-input placeholder="请输入..." v-model="queryParam.wgycj"/>
                  </a-col>
              </a-row>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="专业课一成绩">
                <a-row :gutter="0" style="overflow:hidden">
                  <a-col span="12">
                    <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ywkycjfw">
                      <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                    </a-select>
                  </a-col>
                  <a-col span="12">
                    <a-input placeholder="请输入..." v-model="queryParam.ywkycj"/>
                  </a-col>
              </a-row>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="专业课二成绩">
                <a-row :gutter="0" style="overflow:hidden">
                  <a-col span="12">
                    <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ywkecjfw">
                      <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                    </a-select>
                  </a-col>
                  <a-col span="12">
                    <a-input placeholder="请输入..." v-model="queryParam.ywkecj"/>
                  </a-col>
              </a-row>
            </a-form-item>
          </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="总成绩">
                <a-row :gutter="0" style="overflow:hidden">
                  <a-col span="12">
                    <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.cszcjfw">
                      <a-select-option v-for="(i,j) in scoreList" :key="j" :value="i">{{ i }}</a-select-option>
                    </a-select>
                  </a-col>
                  <a-col span="12">
                    <a-input placeholder="请输入..." v-model="queryParam.cszcj"/>
                  </a-col>
                </a-row>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="考生类型">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.kslx">
                  <a-select-option v-for="i in selectMenu.kslxlb" :key="i.id" :value="i.code">{{ i.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="学习形式">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zhxlxxxs">
                  <a-select-option v-for="i in selectMenu.xxlx" :key="i.id" :value="i.code">{{ i.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="专项计划">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zxjh">
                  <a-select-option key="zxjh01" value="00">非专项生</a-select-option>
                  <a-select-option key="zxjh02" value="01">专项生</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>


            <a-col :sm="{span:12}" :lg="{span:3}" :xl="{span:4}">
              <a-form-item label="数据排序方式">
                <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sortField">
                  <a-select-option v-for="i in selectMenu.sjplfs" :key="i.id" :value="i.code">{{ i.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :sm="{span:24}" :xl="{span:24}">
             <span class="table-page-search-submitButtons" >
            <a-button type="primary" @click="loadData" style="margin: 8px">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
              </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-alert :message="'总条数：' + pagination.total" type="info" show-icon />
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="pagination"
      @change="handleTableChange"
      :scroll="{ x: 3200 }"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
         <template slot="ksbh" slot-scope="text,record">
          <a @click="handlePreview(record.id)">{{text}}</a>
        </template>
        <template slot="action" slot-scope="text,record" >
          <a @click="editScore(record)" v-hasPermission="'ssksxx:update'">修改</a>
        </template>
    </a-table>
      <!-- 查看 -->
      <examinee :previewVisible="previewVisible" :info="examineeData" @close="handleClosePreview"></examinee>
       <query-edit ref="quertEditRef" :info="queryEditData" @close="handleEditClose" @success="handleEditSuccess"
      :editVisibile="editVisibile"></query-edit>
    </a-card>
</div>

</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'
 import Examinee from '../../examinee/detail'
import queryEdit from './queryEdit'
const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    Examinee,
    queryEdit
  },
  data () {
    return {
      advanced: true,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        'ksbh':'',
        'ksxm':'',
        'zzllcjfw':'',
        'zzllcj':'',
        'wgycjfw':'',
        'wgycj':'',
        'ywkycjfw':'',
        'ywkycj':'',
        'ywkecjfw':'',
        'ywkecj':'',
        'cszcjfw':'',
        'cszcj':'',
        'kslx':'',
        'zsnj':'',
        'bkyxsm':'',
        'bkzydm':'',
        'bkyjfxm':'',
        'zhxlxxxs':'',
        'sortField':''
      },
      postParams: {},
      scoreList:['<=','>='],
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' },
           width:100
        },
        {
          title: '准考证号',
          dataIndex: 'ksbh',
          scopedSlots: {
            customRender: 'ksbh'
          },
          width:200
        },
        {
          title: '姓名',
          dataIndex: 'ksxm',
          width:100
        },
        {
          title: '报考院系',
          dataIndex: 'bkyxsmc',
          width:200
        },
        {
          title: '报考专业代码',
          dataIndex: 'bkzydm',
          width:200
        },
        {
          title: '报考专业',
          dataIndex: 'bkzymc',
          width:200
        },
        {
          title: '研究方向',
          dataIndex: 'bkyjfxmc',
          width: 200
        },
        {
          title: '学习形式',
          dataIndex: 'zhxlxxxs',
          width: 150
        },
        {
          title: '专项计划',
          dataIndex: 'zxjhmc',
          width: 200
        },
        {
          title: '科目一',
          dataIndex: 'zzllcj',
          width: 100
        },
        {
          title: '科目二',
          dataIndex: 'wgycj',
          width: 100
        },
        {
          title: '科目三',
          dataIndex: 'ywkycj',
          width:100
        },
        {
          title: '科目四',
          dataIndex: 'ywkecj',
          width:100
        },
        {
          title: '总分',
          dataIndex: 'zf',
          width:100
        },
        {
          title: '总分加分',
          dataIndex: 'zfjf',
          width:150
        },
        {
          title: '复试成绩',
          dataIndex: 'fscj',
          width:150
        },
        {
          title: '综合评定',
          dataIndex: 'zhpd',
          width:150
        },
        {
          title: '报考导师',
          dataIndex: 'bkdsyxm',
          width:150
        },
        {
          title: '综合排名',
          dataIndex: 'zhpm',
          width:150
        },
        {
          title: '是否录取',
          dataIndex: 'lqzt',
          width:150
        },
        {
          title: '录取类别',
          dataIndex: 'lqlbm',
          width:150
        },
        {
          title: '本科毕业时间',
          dataIndex: 'zhxlbyny',
          width:200
        },
        {
          title: '毕业单位',
          dataIndex: 'dxbyxxmc',
           width:150
        },
        {
          title: '政治面貌',
          dataIndex: 'zzmmm',
          width:200
        },
        {
          title: '联系方式',
          dataIndex: 'yddh',
          width:200
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      selectMenu: {
        yx: [],// 院系
        zy: [],
        xxlx: [],
        kslxlb: [],
        sjplfs: [],
        yjfx: [],
      },
      pagination:{
      	current:1,
        showTotal: (() => {return `共 ${this.pagination.total} 条`})
      },
      newParams:{},
      examineeData: {},
      previewVisible: false,
      editVisibile:false,
      queryEditData:''
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.queryParam.wgycjfw = this.queryParam.ywkycjfw = this.queryParam.ywkecjfw =
    this.queryParam.cszcjfw = this.queryParam.zzllcjfw   = this.scoreList[0]
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        this.queryParam.bkyxsm = res[0].data[0].dwh
        this.getProssion(this.queryParam.bkyxsm)
        // 获取学习形式
        this.$api.base.dictionaryData('TYPE0441').then(res => {
        	this.selectMenu.xxlx = res.data
        })
        // 获取考生类型
        this.$api.base.dictionaryData('TYPE0398').then(res => {
        	this.selectMenu.kslxlb = res.data
        })
        // 获取数据排序方式
        this.$api.base.dictionaryData('TYPE0397').then(res => {
        	this.selectMenu.sjplfs = res.data
          this.queryParam.sortField = res.data[0].code
        })
         // 获取当前学年
        this.$api.base.getSchoolYear().then(res=>{
          this.queryParam.zsnj = res.data.masterAdmissionYear
           this.loadData({
            pageSize: 10,
            pageNum: 1
          })
        })
      })

    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'bkzydm', '')
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.selectMenu, 'yjfx', [])
      this.$set(this.selectMenu, 'zy', [])
      if(code){
        this.getProssion(code)
      }
    },
    getProssion(code) {
      this.$api.base.majorAll({
        lsdwh: code
      }).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 选择专业
    zyChange(code){
      this.$set(this.queryParam, 'bkyjfxm', '')
      this.$set(this.selectMenu, 'yjfx', [])
      if(code){
        this.$api.base.searchDirectory({
          ssyxm: this.queryParam.bkyxsm,
          sszym: code,
          zsxn:this.queryParam.zsnj,
           xwccm: 2
        }).then(res => {
          this.$set(this.selectMenu, 'yjfx', res.data)
        })
      }
    },
    xnChange(code){
       this.$set(this.selectMenu, 'yjfx', [])
      this.$set(this.queryParam, 'bkyjfxm', '')
     if(this.queryParam.bkzydm && this.queryParam.bkzydm && code){
        let params={sszym: this.queryParam.bkzydm,ssyxm: this.queryParam.bkyxsm,zsxn:code, xwccm: 2}
        this.$api.base.searchDirectory(params).then(res => {
          this.$set(this.selectMenu, 'yjfx', res.data)
        })
     }
    },
      // 查看考生详情
      handlePreview(code) {
        this.$api.recruitstat.masterAdmissionManageId(code).then(res => {
          this.examineeData = res.data
          this.previewVisible = true
        })
      },
    // 加载数据
    loadData (parameter = {}) {
      if(!parameter.pageNum){
        this.pagination.current = 1
        parameter.pageNum = 1
      }
       this.getParams()
    	let params = Object.assign(this.newParams, parameter)
      this.loading = true;
      this.$api.recruitstat.studentScoreQuery(params).then(res=>{
      	// console.log(res)
      	const pagination = { ...this.pagination
      	};
      	pagination.total = 0
      	if (res.data && res.data.total) {
      	  pagination.total = res.data.total;
      	}
      	this.data = []
      	this.pagination = pagination;
      	if (res.data && res.data.rows.length) {
           res.data.rows.map((item,index) => {
            this.selectMenu.xxlx.map((_item,_index) => {
              if(item.zhxlxxxs == _item.code){
                item.zhxlxxxsmc = _item.name
              }
            })
            return item;
          })
      	  this.data = res.data.rows;
      	}
      	this.loading = false;
      })
    },
    getParams(){
      this.newParams = {}
      for(var item in this.queryParam){
        if(item != 'zzllcjfw' && item != 'wgycjfw' && item != 'ywkycjfw' && item != 'ywkecjfw' && item != 'cszcjfw' ){
          this.newParams[item] = this.queryParam[item]
        }
      }
      this.queryParam.zzllcj? (this.queryParam.zzllcjfw =='>=' ? this.newParams.zzllcjd = '01' :this.newParams.zzllcjx = '01'):''
     this.newParams.wgycj ?  (this.queryParam.wgycjfw =='>=' ? this.newParams.wgycjd = '01' :this.newParams.wgycjx = '01'):''
     this.newParams.ywkycj ?  (this.queryParam.ywkycjfw =='>=' ? this.newParams.ywkycjd = '01' :this.newParams.ywkycjx = '01'):''
     this.newParams.ywkecj ?  (this.queryParam.ywkecjfw =='>=' ? this.newParams.ywkecjd = '01' :this.newParams.ywkecjx = '01'):''
     this.newParams.cszcj ?  (this.queryParam.cszcjfw =='>=' ? this.newParams.cszcjd = '01' :this.newParams.cszcjx = '01'):''
    },
    // 分页
    handleTableChange (pagination, filters, sorter) {
    	console.log(pagination);
    	const pager = { ...this.pagination };
    	pager.current = pagination.current;
    	this.pagination = pager;
    	this.loadData({
    		pageSize: 10,
    		pageNum: pagination.current
    	});
    },
    // 关闭考生想去
      handleClosePreview() {
        this.previewVisible = false
      },
    // 导出
    handleExport () {
      console.log('导出')
      this.$export('admissions/ssksxxcx/export',this.newParams)
    },
    editScore(code){
      this.editVisibile = true
      this.queryEditData = code


    },
    handleEditClose(){
      this.editVisibile = false
    },
    handleEditSuccess(){
      this.editVisibile = false
      this.loadData({
        pageNum:1,
        pageSize:10
      })
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
